﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using HYRElectric.Equipment;

namespace HYRElectric.PowerSystem
{
	public partial class DlgEquipTypeSelect : System.Windows.Forms.Form
	{
		public DlgEquipTypeSelect(Dictionary<EquipmentType, string> dictEquipmentType, EquipmentType defaultType)
		{
			this.InitializeComponent();
			this.m_dictEquipmentType = dictEquipmentType;
			this.m_defaultType = defaultType;
		}

		private void DlgEquipTypeSelect_Load(object sender, EventArgs e)
		{
			int num = 0;
			this.checkedListBox1.Items.Clear();
			foreach (KeyValuePair<EquipmentType, string> keyValuePair in this.m_dictEquipmentType)
			{
				this.checkedListBox1.Items.Add(keyValuePair.Value);
				if (this.m_defaultType == keyValuePair.Key)
				{
					this.checkedListBox1.SetItemChecked(num, true);
					this.checkedListBox1.SelectedIndex = num;
				}
				num++;
			}
		}

		private void btnOK_Click(object sender, EventArgs e)
		{
			int selectedIndex = this.checkedListBox1.SelectedIndex;
			if (selectedIndex < 0)
			{
				return;
			}
			this.m_selType = (EquipmentType)selectedIndex;
			base.DialogResult = DialogResult.OK;
		}

		private void SetSelectListChecked()
		{
			int selectedIndex = this.checkedListBox1.SelectedIndex;
			if (selectedIndex < 0)
			{
				return;
			}
			for (int i = 0; i < this.checkedListBox1.Items.Count; i++)
			{
				this.checkedListBox1.SetItemChecked(i, i == selectedIndex);
			}
		}

		private void checkedListBox1_DoubleClick(object sender, EventArgs e)
		{
			this.SetSelectListChecked();
			if (this.checkedListBox1.SelectedIndex < 0)
			{
				return;
			}
			this.btnOK_Click(sender, e);
		}

		private void checkedListBox1_SelectedValueChanged(object sender, EventArgs e)
		{
			this.SetSelectListChecked();
		}

		private void checkedListBox1_MouseClick(object sender, MouseEventArgs e)
		{
			this.SetSelectListChecked();
		}

		private Dictionary<EquipmentType, string> m_dictEquipmentType = new Dictionary<EquipmentType, string>();

		private EquipmentType m_defaultType;

		public EquipmentType m_selType;
	}
}
